import { createRouter, createWebHistory } from "vue-router";
import Login from "@/pages/login.vue";
import Register from "@/pages/register/registerIndex.vue"
import Dashboard from "@/pages/dashboard/dashboard.vue";
import { useRouter } from 'vue-router';

export const routes = [
  {
    path: "/",
    redirect: "/publicity",
  },
  // {
  //   name: "login",
  //   path: "/login",
  //   component: Login,
  // },
  {
    name: "register",
    path: "/register",
    component: Register,
  },

  {
    name: "index",
    path: "/index",
    component: () => import("@/pages/index.vue"),
    redirect: "/dashboard",
    children: [
      {
        path: "/dashboard",
        component: Dashboard,
        name: "dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
      },
      {
        path: "/map",
        component: () => import("@/pages/map/map.vue"),
        name: "map",
      },
      {
        path: "/followTrend",
        component: () => import("@/pages/follow-trend/follow-trend.vue"),
        name: "followTrend", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
      },
      {
        path: "/notice",
        component: () => import("@/pages/message/index.vue"),
        name: "notice", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        redirect: "/message",
        children: [
          {
            path: "/message",
            component: () => import("@/pages/message/children/message.vue"),
            name: "message", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
          },
          {
            path: "/agreeCollection",
            component: () => import("@/pages/message/children/agree-collection.vue"),
            name: "agreeCollection", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
          },
          {
            path: "/follower",
            component: () => import("@/pages/message/children/follower.vue"),
            name: "follower", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
          },
          {
            path: "/comment",
            component: () => import("@/pages/message/children/comment.vue"),
            name: "comment", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
          },
          {
            path: "/chat",
            component: () => import("@/pages/chat/index.vue"),
            name: "chat", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
          },
        ],
      },
      {
        path: "/user",
        component: () => import("@/pages/user/index.vue"),
        name: "user",
        redirect: "/user/note",  // 修改重定向到完整路径
        children: [
          {
            path: "note",  // 相对路径（实际路径会是 /user/note）
            component: () => import("@/pages/user/children/note.vue"),
            name: "userNote",
          },
          {
            path: "collection",
            component: () => import("@/pages/user/children/collection.vue"),
            name: "userCollection",
          },
          {
            path: "order",
            component: () => import("@/pages/user/children/order.vue"),
            name: "user.order",
          },
          {
            path: "useraddrs",
            component: () => import("@/pages/user/children/userAddrs.vue"),
            name: "userAddrs",
          },
        ],
      },
      // 添加他人主页路由
      {
        path: "/otherUser",
        component: () => import("@/pages/otherUser/otherUserIndex.vue"),
        name: "otherUser",
        children: [
          {
            path: "",  // 默认子路由
            component: () => import("@/pages/otherUser/children/otherNote.vue"),
            name: "otherUserNote",
          }
        ],
      },
      // 发布中心路由
      {
        path: "/push",
        component: () => import("@/pages/push/pushIndex.vue"),
        name: "push",
        redirect: "/push/note",
        children: [
          {
            path: "note",
            component: () => import("@/pages/push/notePush.vue"),
            name: "push.note",
          },
          {
            path: "disaster",
            component: () => import("@/pages/push/disasterPush.vue"),
            name: "push.disaster",
          },
          {
            path: "secondhand",
            component: () => import("@/pages/push/secondHandPush.vue"),
            name: "push.secondhand",
          },
        ],
      },
      {
        path: "/secondhand",
        component: () => import("@/pages/secondhand/index.vue"),
        name: "secondhand",
      },
      {
        path: "/secondhand/search",
        component: () => import("@/pages/secondhand/searchSecondHandPage.vue"),
        name: "secondhand.search",
      },
      {
        path: "/secondhand/detail/:id",
        component: () => import("@/pages/secondhand/detail.vue"),
        name: "secondhand.detail",
      },
      {
        path: "/secondhand/confirm/:id",
        component: () => import("@/pages/secondhand/confirmOrder.vue"),
        name: "secondhand.confirm",
      },
      {
        path: "/secondhand/order/:id",
        component: () => import("@/pages/secondhand/orderDetail.vue"),
        name: "secondhand.order",
      },
      {
        path: "/secondhand/complete/:id",
        component: () => import("@/pages/secondhand/completePurchase.vue"),
        name: "secondhand.complete",
      },
      {
        path: "/search",
        component: () => import("@/pages/dashboard/searchArticlePage.vue"),
        name: "search",
      },
    ],
  },
  {
    name: "main",
    path: "/main",
    component: () => import("@/pages/main.vue"),
    props: (route) => ({ 
      articleID: route.query.id,
      isModal: true, // 标记为模态窗口模式
      returnPath: route.query.returnPath || '/dashboard' // 返回路径
    })
  },
  {
    name: "publicity",
    path: "/publicity",
    component: () => import("@/pages/publicityPage/publicityHome.vue"),
  },
  {
    name: "AIRecognition",
    path: "/aiRecognition",
    component: () => import("@/pages/AIrecognition/AIRecognitionPage.vue"),
  },
  //创作中心
  {
    path: '/platform',
    name: 'platform',
    component: () => import('@/pages/PlatForm/PlatFormView.vue'),
    children:[
      {
        path: '',
        redirect:'/platform/home',
      },
      {
        //投稿
        path: 'upload',
        name: 'platform.upload',
        component: () => import('@/pages/PlatForm/views/UploadView/UploadView.vue'),
        children: [
          {
            path: '',
            redirect: '/platform/upload/note',
          },
          {
            path: 'note',
            name: 'platform.upload.note',
            component: () => import('@/pages/push/notePush.vue'),
          },
          {
            path: 'disaster',
            name: 'platform.upload.disaster',
            component: () => import('@/pages/push/disasterPush.vue'),
          },
          {
            path: 'secondhand',
            name: 'platform.upload.secondhand',
            component: () => import('@/pages/push/secondHandPush.vue'),
          }
        ]
      },
      {
        //首页
        path: 'home',
        name: 'platform.home',
        component: () => import('@/pages/PlatForm/views/PlatFormHome/PlatFormHomeView.vue'),
      },
      {
        //数据看板
        path: 'dataBoard',
        name: 'platform.dataBoard',
        component: () => import('@/pages/PlatForm/views/DataBoard/DataBoardView.vue'),
      },
      {
        //数据图表
        path: 'dataChart',
        name: 'platform.dataChart',
        component: () => import('@/pages/PlatForm/views/DataBoard/DataBoardSplitTabView.vue'),
      },
      {
        //内容管理->稿件管理
        path: 'upload-manager/article',
        name: 'platform.article',
        component: () => import('@/pages/PlatForm/views/UploadManageView/UploadManageView.vue'),
      },
      {
        //互动管理->评论管理
        path: 'interact/comment',
        name: 'platform.comment',
        component: () => import('@/pages/PlatForm/views/CommentManageView/CommentManageView.vue'),
      },
      {
        //编辑文章
        path: 'upload-manager/edit-article/:id',
        name: 'platform.editArticle',
        component: () => import('@/pages/PlatForm/views/UploadManageView/EditArticleView.vue'),
      },
      {
        //内容管理->灾害管理
        path: 'upload-manager/disaster',
        name: 'platform.disaster',
        component: () => import('@/pages/PlatForm/views/DisasterManageView/DisasterManageView.vue'),
      },
      {
        //内容管理->二手商品管理
        path: 'upload-manager/item',
        name: 'platform.itemManager',
        component: () => import('@/pages/PlatForm/views/ItemManageView/ItemManageView.vue'),
      },
    ]
  },
  {
    name: "communityRules",
    path: "/community-rules",
    component: () => import("@/pages/communityRules/communityRulesView.vue"),
  },
];
const router = createRouter({
  scrollBehavior: () => ({ left: 0, top: 0 }),
  history: createWebHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  next();
});
export default router;
